package com.joseph.user.manager.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.joseph.common.exception.BizException;
import com.joseph.user.mapperservice.IUserService;
import com.joseph.user.po.User;
import com.joseph.user.manager.IUserManager;
import com.joseph.user.dto.request.UserReq;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@AllArgsConstructor
public class UserManager implements IUserManager {

    private final IUserService userService;

    @Override
    public User getUser(Integer id) {
        return userService.getById(id);
    }

    @Override
    public void addUser(User user) {
        User u = new User();
        u.setAge(32);
        u.setName("momo");
        userService.save(u);
    }

    @Override
    public void login(UserReq loginDTO) {
        User one = userService.getOne(Wrappers.lambdaQuery(User.class)
                .eq(User::getName, loginDTO.getPassword())
                .eq(User::getPassword, loginDTO.getPassword()));
        if (one == null) {
            throw new BizException("用户信息失败");
        }

    }
}
